package com.leetcode.algorithm.y22.m06;

/**
 * 1232. 缀点成线
 * 
 * https://leetcode.cn/problems/check-if-it-is-a-straight-line/
 * 
 * @author jie.deng
 *
 */
class Question1232Solution01 {
	
	public boolean checkStraightLine(int[][] coordinates) {
		int len = coordinates.length;
		if (len == 2) {
			return true;
		}
		int[] p0 = coordinates[0];
		int[] p1 = coordinates[1];
		int y = p1[1] - p0[1];
		int x = p1[0] - p0[0];
		for (int i = 2; i < coordinates.length; i++) {
			int[] pi = coordinates[i];
			if (((pi[1] - p0[1]) * x) != ((pi[0] - p0[0]) * y)) {
				return false;
			}
		}
		return true;
	}
    
}